import android.app.Activity
import com.mechat.BuildConfig
import io.rong.imkit.SpName
import com.mechat.ui.login.LoginActivity
import com.google.firebase.messaging.FirebaseMessaging
import com.custom.base.config.BaseConfig
import com.custom.base.manager.SDActivityManager
import com.custom.base.util.IntentUtil
import io.rong.imkit.RongIM
import org.json.JSONObject

object UserUtil {
    /**
     * 退出登录
     */
    fun out(context:Activity) {
        val jsonObject = JSONObject()
        jsonObject.put("channel","l1")
        jsonObject.put("appCode","sparksy")
        jsonObject.put("appVersion", BuildConfig.VERSION_CODE)
        jsonObject.put("token","")
        BaseConfig.getInstance.addHead("basicParams", jsonObject.toString())
        BaseConfig.getInstance.setString(SpName.token, "")
        BaseConfig.getInstance.setString(SpName.userCode, "")
        FirebaseMessaging.getInstance().deleteToken()
        RongIM.getInstance().logout()
        IntentUtil.startActivity(LoginActivity::class.java, activity = context)
        SDActivityManager.instance.finishAllActivityExcept(LoginActivity::class.java)
    }


    fun startLogin(activity: Activity?){
        IntentUtil.startActivity(LoginActivity::class.java, activity = activity)
        SDActivityManager.instance.finishAllActivityExcept(LoginActivity::class.java)
    }

}